
package pe.edu.pucp.Maestros.DAO;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import pe.edu.pucp.Modelo.TipoAvion;
import pe.edu.pucp.Util.HibernateUtil;
/**
 *
 * @author oscar
 */
public class TipoAvionDAO {
    public void guardarTipoAvion(TipoAvion c) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx =  session.beginTransaction();
        session.save(c);
        tx.commit();
        session.close();
    }
    
    public ArrayList<TipoAvion> listarTipoAvion() {
        ArrayList<TipoAvion> lstTipoAvion = new ArrayList<>();
        
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();        
        List lista = session.createQuery("from TipoAvion").list();
        for ( Iterator iter = lista.iterator(); iter.hasNext(); ) {    
            TipoAvion doc = (TipoAvion) iter.next();
            lstTipoAvion.add(doc);
        }        
        tx.commit();
        session.close();
        return lstTipoAvion;
    }
        
    public void actualizarTipoAvion(TipoAvion c) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx =  session.beginTransaction();
            session.update(c);
        tx.commit();
        session.close();
    }
}
